package com.syc.test.entity;

import org.apache.commons.lang3.StringUtils;

import java.util.*;

/***
 * 文章媒体类型菜单
 * baiqy
 * **/
public enum ArticleTypeMenu {

    SINA("0", "微博", "101"),
    NEWS_SITE("1", "网站", "103"),
    WE_CHAT("2", "微信", "102"),
    BBS("3", "互动论坛", "104"),
    BLOG("4", "互动论坛", "104"),
    NEWS_PAPER("5", "数字报", "106"),
    VIDEO("6", "视频", "107"),
    QQ("7", "微信", "102"),
    POSTER("8", "互动论坛", "104"),
    ABROAD("9", "境外", "108"),
    TWITTER("10", "境外", "108"),
    NEWS_CLIENT("11", "客户端", "105"),
    TELEGRAPH("15", "境外", "108"),
    YOUTUBE("16", "境外", "108"),
    DOUYIN("17", "抖音", "109"),
    REDBOOK("18", "小红书", "110"),
    TOUTIAO("19", "今日头条", "111"),
    KUAISHOU("20", "快手", "112"),
    ;
    private final String articleType;
    private final String articleTypeValue;
    /**
     * 新媒体类型code
     */
    private final String mediaCode;

    public String getMediaCode() {
        return mediaCode;
    }

    public String getArticleType() {
        return articleType;
    }

    public String getArticleTypeValue() {
        return articleTypeValue;
    }

    ArticleTypeMenu(String articleType, String articleTypeValue, String mediaCode) {
        this.articleType = articleType;
        this.articleTypeValue = articleTypeValue;
        this.mediaCode = mediaCode;
    }

    public static void main(String[] args) {
        for (int i = 0; i < values().length; i++) {
            ArticleTypeMenu typeMenu = values()[i];
            System.out.println(typeMenu.getArticleType()+"-"+typeMenu.getArticleTypeValue());
        }
    }

    public static Map<String, String> getAllToMap() {
        Map<String, String> articleTypeMap = new HashMap<>();
        for (ArticleTypeMenu menu : values()) {
            articleTypeMap.put(menu.articleType, menu.articleTypeValue);
        }
        return articleTypeMap;
    }

    public static List<String> getALLArticleType() {
        List<String> articleTypeList = new ArrayList<>();
        for (ArticleTypeMenu menu : values()) {
            articleTypeList.add(menu.articleType);
        }
        return articleTypeList;
    }

    public static ArticleTypeMenu getInstanceByOrigin(String originName) {
        final List<String> videoInclude = Arrays.asList("抖音", "豆瓣", "快手");
        final List<String> newsPaper = Arrays.asList("日报", "晚报", "快报", "午报", "早报", "时报");
        final List<String> appList = Arrays.asList("客户端", "今日头条", "小红书");
        if (originName.contains(SINA.articleTypeValue)) {
            return SINA;
        } else if (originName.contains(WE_CHAT.articleTypeValue)) {
            return WE_CHAT;
        } else if (originName.contains(VIDEO.articleTypeValue) || videoInclude.contains(originName)) {
            return VIDEO;
        } else if (StringUtils.containsIgnoreCase("APP", originName) || appList.contains(originName)) {
            return NEWS_CLIENT;
        } else if (newsPaper.contains(originName)) {
            return NEWS_PAPER;
        } else if ("报".contains(originName)) {
            return TELEGRAPH;
        } else if (BBS.getArticleTypeValue().contains(originName)) {
            return BBS;
        } else if (BLOG.getArticleTypeValue().contains(originName)) {
            return BLOG;
        } else if ("海外".contains(originName)) {
            return ABROAD;
        } else if (StringUtils.containsIgnoreCase(QQ.getArticleTypeValue(), originName)) {
            return QQ;
        } else if (StringUtils.containsIgnoreCase(TWITTER.getArticleTypeValue(), originName)) {
            return TWITTER;
        } else if (StringUtils.containsIgnoreCase(YOUTUBE.getArticleTypeValue(), originName)) {
            return YOUTUBE;
        } else {
            return NEWS_SITE;
        }
    }

    public static boolean isAbroad(String articleType) {
        if (StringUtils.isNotBlank(articleType)) {
            if (ABROAD.articleType.equals(articleType)
                    || TWITTER.articleType.equals(articleType)
                    || TELEGRAPH.articleType.equals(articleType)
                    || YOUTUBE.articleType.equals(articleType)) {
                return true;
            }
        }
        return false;
    }

    public static String getArticleTypeByMediaCode(String mediaCode) {
        if (StringUtils.isNotBlank(mediaCode)) {
            for (ArticleTypeMenu value : values()) {
                if (mediaCode.equals(value.getMediaCode())) {
                    return value.articleType;
                }
            }
        }
        return "-1";
    }

    public static String getArticleTypeByArticleTypeValue(String articleTypeValue) {
        if (StringUtils.isNotBlank(articleTypeValue)) {
            for (ArticleTypeMenu value : values()) {
                if (articleTypeValue.equals(value.getArticleTypeValue())) {
                    return value.articleType;
                }
            }
        }
        return "-1";
    }

    public static String getArticleTypeValueByMediaCode(String mediaCode) {
        if (StringUtils.isNotBlank(mediaCode)) {
            for (ArticleTypeMenu value : values()) {
                if (mediaCode.equals(value.getMediaCode())) {
                    return value.articleTypeValue;
                }
            }
        }
        return null;
    }

    public static String getArticleTypeValueByArticleType(String articleType) {
        if (StringUtils.isNotBlank(articleType)) {
            for (ArticleTypeMenu value : values()) {
                if (articleType.equals(value.getArticleType())) {
                    return value.articleTypeValue;
                }
            }
        }
        return null;
    }

    public static String getMediaCodeByArticleType(String articleType) {
        if (StringUtils.isNotBlank(articleType)) {
            for (ArticleTypeMenu value : values()) {
                if (articleType.equals(value.getArticleType())) {
                    return value.mediaCode;
                }
            }
        }
        return null;
    }

}
